#ifndef BACKGROUNDWORKER_H
#define BACKGROUNDWORKER_H

#include <QObject>
#include <QThread>
#include <QMetaObject>
#include <QMetaMethod>

class BackgroundWorker : public QObject
{
    Q_OBJECT
public:
    explicit BackgroundWorker(QObject *parent) :
        QObject(parent){
        originalThread = QThread::currentThread();
    }

    ~BackgroundWorker() {
        backgroundWorkerThread.quit();
        backgroundWorkerThread.wait();
    }

    void deleteLater() {
        moveToThread(originalThread);
        QObject::deleteLater();
    }

    void runInBackground(const char *slot, QHash<QString, QVariant> args = QHash<QString, QVariant>() );

public slots:

signals:
    void doWork();

protected:
    QHash<QString, QVariant> args;

public:
    QThread backgroundWorkerThread;
    QThread *originalThread;
};


#endif // BACKGROUNDWORKER_H
